/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mythinking;

import java.util.Vector;
/**
 *
 * @author jzou
 */
public class Grid {

    Vector nodes = new Vector();
    Object gridObjects[][] = new Object[100][100];

    public void generate() {
        int x = 0;
        int y = 0;
        Vector root = new Vector(4);
        int level = 0;
        _generate(root, "/", x, y, level);
    }

    public void _generate(Vector node, String path, int x, int y, int level) {
        System.out.println("Path=" + path + "/[x=" + x + ", y=" + y + "]");
        if (level < 4) {
            for (int i = 0; i < 4; i++) {
                long randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                Vector subNode = new Vector(4);
                node.add(subNode);
                String nextPath;
                String nodeName = Integer.toString(x)+","+Integer.toString(y);
                if ( level ==0 )
                    nextPath = path + nodeName;
                else
                    nextPath = path + "/" + nodeName;
                switch (i) {
                    case 0: // up
                        _generate(subNode, nextPath, x - (int)randInt, y, level + 1);
                        break;
                    case 1: // down
                        _generate(subNode, nextPath, x + (int)randInt, y, level + 1);
                        break;
                    case 2: // left
                        _generate(subNode, nextPath, x , y - (int)randInt, level + 1);
                        break;
                    case 3: // right
                        _generate(subNode, nextPath, x , y + (int)randInt, level + 1);
                        break;
                }
            }
        }
    }

    public static void main(String[] args) {
        Grid grid = new Grid();
        grid.generate();
    }
    
    public static void arrayDemo(String[] args) {
        Grid grid = new Grid();
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                long randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                Vector node = new Vector(4);
                randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                node.add(randInt);  // up
                randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                node.add(randInt);  // down
                randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                node.add(randInt);  // left
                randInt = java.lang.Math.round(java.lang.Math.random() * 100);
                node.add(randInt);  // right
                grid.gridObjects[i][j] = node;
            }
        }
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                System.out.print(grid.gridObjects[i][j] + " ");
            }
            System.out.println();
        }
    }
}
